package com.ycy;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ExcelExportTestData {

    @Test
    public void test02() {
            //表头list的生成，实际的表头信息可以从数据库或者缓存等处动态读取
            List<List<String>> headList = new ArrayList<List<String>>();
            List<String> head0 = new ArrayList<String>();
            //第一层
            head0.add("用户");
            //第二层
            head0.add("名称");
            List<String> head1 = new ArrayList<String>();
            //第一层
            head1.add("用户");
            //第二层
            head1.add("年龄");
            List<String> head2 = new ArrayList<String>();
            //第一层
            head2.add("用户");
            //第二层
            head2.add("性别");

            headList.add(head0);
            headList.add(head1);
            headList.add(head2);


            List<String> head3 = new ArrayList<String>();
            head3.add("手机号");
            List<String> head4 = new ArrayList<String>();
            //第一层
            head4.add("地址");
            //第二层
            head4.add("国家");
            List<String> head5 = new ArrayList<String>();
            //第一层
            head5.add("地址");
            //第二层
            head5.add("省份");

            headList.add(head3);
            headList.add(head4);
            headList.add(head5);


// 2. 写入数据
        List<List<Object>> data = new ArrayList<>();

        data.add(Arrays.asList("张三", 25, "男"));
        String filePath = System.getProperty("user.home") + "/Desktop/linshi/test.xlsx";

// 3. 执行导出
        EasyExcel.write("output.xlsx")
                .head(headList)
                .sheet("用户数据")
                .doWrite(data);

    }


    @Test
    public void test01() {

        /**
         * 生成测试数据
         */
        List<RaInfoTownUploadExcel> entityList = new ArrayList<>();

        for (int i = 0; i < 100000; i++) {
            RaInfoTownUploadExcel entity = new RaInfoTownUploadExcel();
            entity.setOrder(String.valueOf(i + 1));
//                        .setEntCity("City" + (i % 100));
//                        .setEntDistrict("District" + (i % 100));
//                        .setEntName("Enterprise" + (i % 1000));
//                        .setEntCreditCode(UUID.randomUUID().toString());
//                        .setBusinessLicense("License" + (i % 1000));
//                        .setCode("Code" + (i % 1000));
            entity.setRegion("长安区");
            entity.setName("十万" + i);
            entity.setAlias("Alias" + (i % 1000));
            entity.setCodeExtsys("ExtCode" + (i % 1000));
            entity.setStreetOffice("StreetOffice" + (i % 100));
            entity.setAddress("Address" + (i % 1000));
            entity.setResCount(String.valueOf((i % 1000) + 1));
            entity.setGcPlCount(String.valueOf((i % 500) + 1));
            entity.setGcBtCount(String.valueOf((i % 300) + 1));
            entity.setCheckConcentrationDeviceCount(String.valueOf((i % 200) + 1));
            entity.setReportAndCloseDeviceCount(String.valueOf((i % 150) + 1));
            entity.setSmartCloseDeviceCount(String.valueOf((i % 100) + 1));
            entity.setIcGasFlowMeterCount(String.valueOf((i % 80) + 1));
            entity.setDiaphragmGasFlowMeterCount(String.valueOf((i % 60) + 1));
            entity.setIocGasFlowMeterCount(String.valueOf((i % 40) + 1));
            entity.setLongitude(String.valueOf(100 + (i % 100) * 0.01));
            entity.setLatitude(String.valueOf(30 + (i % 100) * 0.01));
            entity.setRemark("Remark" + (i % 1000));

            entityList.add(entity);
        }

        // 桌面路径
        String filePath = System.getProperty("user.home") + "/Desktop/居住区10w测试数据.xlsx";

        EasyExcel.write(filePath)
                .head(RaInfoTownUploadExcel.class)
                .excelType(ExcelTypeEnum.XLSX)
                .sheet("居住区（村庄）档案")
                .doWrite(entityList);

        // Output the size of the list to verify
        System.out.println("Number of entities created: " + entityList.size());
    }

}
